
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
npm install zpromise
消除Promise注入函数,可通过Promise实例直接访问resolve()或reject()
支持获取当前Promise实例状态
支持Promise超时触发reject()
支持Promise快速解除、重置
const zPromise = require('zpromise');
async function () {
let promise = new zPromise()
setTimeout(() => {
if (error) {
promise.reject(error)
} else {
promise.resolve(data)
}
}, 1000);
await promise.catch(error => {
console.error(error)
})
}
const timerPromise = require('zpromise/timer');
async function run(params) {
let promise = new timerPromise(3000)
console.log(promise.state)
await promise.catch(error => {
console.error(error)
})
console.log(promise.state)
}
run()
const restartPromise = require('zpromise/restart');
async function run(params) {
let p1 = new restartPromise(3000 , error => {
console.warn('等待超时')
})
await p1.catch(error => {
console.error(error)
})
let p2 = p1.restart()
p2.then(data => {
console.error(data)
}).catch(error => {
console.error(error)
})
setTimeout(() => {
p2.reject()
}, 1000);
}
run()
Promise简化包装,提供resolve、reject绑定和状态查询
Promise实例状态,包含pending、resolve、reject三种状态
对应Promise注入函数中的resolve()
对应Promise注入函数中的reject()
在zPromise基础上增加了定时器功能,在等待超时后自动调用预设的reject()或resolve(),原型属性与zPromise一致。
delay
Number 超时时间,单位ms,可选
catchFunc
Function 异常捕获回调函数
重置Promise,将原来的Promise改为resolve状态,并使用之前的配置项创建新的Promise实例
FAQs
ES6 Promise简化包装器,用于增强Promise功能和易用性
The npm package zpromise receives a total of 3 weekly downloads. As such, zpromise popularity was classified as not popular.
We found that zpromise demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.